<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
<script>
    // 闭包 实现函数只执行一次
    function once(fn) {
        let called = false
        return function _once() {
            if(called){
                return _once.value
            }

            called = true
            _once.value = fn.apply(this.arguments)
        }
    }

    let index = 0

    const increment = () => index++

    const val = once(increment)

    val()

    val()

    console.log(index);

</script>
<body>
</html>